<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commonjsp/jstl.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>公司级报表</title>
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="stylesheet" type="text/css" href="${prefix}/stylesheets/theme.css">
<link rel="stylesheet" type="text/css" href="${prefix}/stylesheets/reveal.css">
<link rel="stylesheet" type="text/css" href="${prefix}/lib/font-awesome/css/font-awesome.css">
<link rel="stylesheet" type="text/css" href="${prefix}/lib/bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="${prefix}/lib/jqueryui/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="${prefix}/lib/jqueryui/jquery-ui.structure.css">
<link rel="stylesheet" type="text/css" href="${prefix}/lib/jqueryui/jquery-ui.theme.css">

<script src="${prefix}/lib/jquery-1.8.1.min.js" type="text/javascript"></script>
<script src="${prefix}/lib/ajaxfileupload.js" type="text/javascript"></script>
<script src="${prefix}/lib/jquery-form.js" type="text/javascript"></script>
<script src="${prefix}/lib/jquery.reveal.js" type="text/javascript"></script>
<script src="${prefix}/lib/jqueryui/jquery-ui.js" type="text/javascript"></script>
<script src="${prefix}/lib/jqueryui/jquery.ui.datepicker-zh-TW.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function () {
	//页面准备好以后，查询该操作者可以进行操作的公司信息
	queryCompanySelect();
	
	//当公司选择发生变化时
	$("#companyandstoreSelect").change(function() {
		$("#workNumber").val("");
		$("#beginFilingTime").val("");
		$("#endFilingTime").val("");
		$("#reportResultTbody").html("<tr><td colspan=\"6\">请填写报表条件后，点击“search”按钮进行查询。</td></tr>")
		$("#reportUsergroupTbody").html("<tr><td colspan=\"4\">请填写报表条件后，点击“search”按钮进行查询。</td></tr>")
		$("#userperformancepagination").html("");
		$("#listpagination").html("");
	});
	
	//初始化时间控件
	$("#beginFilingTime").datepicker({
		showOtherMonths: true,
		selectOtherMonths: true,
		changeMonth: true,
		changeYear: true
	});
	$("#endFilingTime").datepicker({
		showOtherMonths: true,
		selectOtherMonths: true,
		changeMonth: true,
		changeYear: true
	});
	$("#beginFilingTime").datepicker("option",$.datepicker.regional["zh-TW"]);
});

//查询这个用户可用的公司信息（可维护的公司信息）
function queryCompanySelect() {
	$.ajax({
		type: "post",
		async: true,
		url: "${prefix}/company/queryCompany",
		success: function(data) {
			var jsonData = eval('(' + data + ')');
			var listDatas = jsonData.data;
			var optionhtml = "";
			
			//开始构建公司
			for(var index = 0 ; listDatas != null && index < listDatas.length ; index++) {
				var optionItem = listDatas[index];
				
				optionhtml += "<option value=\"" + optionItem.uid + "\" label=\"" + optionItem.companyName + "\" style=\"color: #FF00FF;margin: 2px\" ";
				if(index == 0) {
					optionhtml += " selected ";
				}
				optionhtml += ">" + optionItem.companyName + "</option>";
			}
			
			$("#companyandstoreSelect").html(optionhtml);
			//初始化后，不进行任何数据的查询，直到用户输入了查询条件，并点击“查询”按钮
		}
	});
}

//按照查询条件，查询指定范围的报表信息(工单统计)
function queryCompanyReport(pageNum) {
	var maxrow = 2;
	//首先，时间范围是必须有的
	var beginFilingTime = $.trim($("#beginFilingTime").val());
	var endFilingTime = $.trim($("#endFilingTime").val());
	if(beginFilingTime == "" || endFilingTime == "") {
		alert("请选择时间返回，时间范围最大跨度为1年！");
		return;
	}
	
	var companyid = $("#companyandstoreSelect").val();
	var data = "companyid=" + companyid + "&beginFilingTime=" + beginFilingTime + "&endFilingTime=" + endFilingTime;
	var workNumber = $.trim($("#workNumber").val());
	if(workNumber != "") {
		data += "&workNumber=" + workNumber;
	}
	
	//分页信息
	if(pageNum == null) {
		data += "&pageNum=0";
	} else {
		data += "&pageNum=" + pageNum;
	}
	data += "&maxrow=" + maxrow;
	
	//开始查询=================工单任务统计
	$.ajax({
		type: "post",
		async: true,
		dataType: "json",
		url: "${prefix}/report/reportOrderInfoByCompany",
		data: data,
		success: function(data) {
			//错误信息
			if(data.responsecode != "E200") {
				alert(data.errorinfo);
				return;
			}
			
			var listDatas = data.data.results;
			//构建数据
			$("#reportResultTbody").html("");
			
			var optionhtml = "";
			for(var index = 0 ; listDatas != null && index < listDatas.length ; index++) {
				var orderinfo = listDatas[index];
				optionhtml += "<tr>";
				optionhtml += "<td>" + orderinfo.orderType.orderTypeName + "[" + orderinfo.orderType.orderCode + "]</td> ";
				optionhtml += "<td>" + orderinfo.realIntegral + "</td>";
				optionhtml += "<td>" + orderinfo.realTotalAmount + "</td>";
				optionhtml += "<td>" + orderinfo.filingTime + "</td>";
				optionhtml += "<td>" + orderinfo.waiter.realName + "[" + orderinfo.waiter.workNumber + "]</td>";
				optionhtml += "</tr>";
			}
			$("#reportResultTbody").html(optionhtml);
			
			//构造上一页和下一页选项
			var optionhtml = "<ul>";
			if(pageNum != 0) {
				optionhtml += "<li><a href=\"javascript:void(0)\" onclick=\"queryCompanyReport(" + (pageNum-1) + ")\">&lt;&lt; Prev</a></li>";
			}
			if(listDatas != null && listDatas.length == maxrow) {
				optionhtml += "<li><a href=\"javascript:void(0)\" onclick=\"queryCompanyReport(" + (pageNum+1) + ")\">Next &gt;&gt;</a></li>";
			}
			optionhtml += "</ul>";
			$("#listpagination").html(optionhtml);
		}
	});
}

//按照查询条件，查询指定范围的报表信息(工单统计)
function queryCompanyReportPerformance(pageNum) {
	var maxrow = 2;
	//首先，时间范围是必须有的
	var beginFilingTime = $.trim($("#beginFilingTime").val());
	var endFilingTime = $.trim($("#endFilingTime").val());
	if(beginFilingTime == "" || endFilingTime == "") {
		alert("请选择时间返回，时间范围最大跨度为1年！");
		return;
	}
	
	var companyid = $("#companyandstoreSelect").val();
	var data = "companyid=" + companyid + "&beginFilingTime=" + beginFilingTime + "&endFilingTime=" + endFilingTime;
	var workNumber = $.trim($("#workNumber").val());
	if(workNumber != "") {
		data += "&workNumber=" + workNumber;
	}
	
	//分页信息
	if(pageNum == null) {
		data += "&pageNum=0";
	} else {
		data += "&pageNum=" + pageNum;
	}
	data += "&maxrow=" + maxrow;
	
	//开始查询=================人员绩效
	$.ajax({
		type: "post",
		async: true,
		dataType: "json",
		url: "${prefix}/report/reportTotalUserGroupByCompany",
		data: data,
		success: function(data) {
			//错误信息
			if(data.responsecode != "E200") {
				alert(data.errorinfo);
				return;
			}
			var listDatas = null;
			if(data.data != null) {
				listDatas = data.data.results;
			}
			 
			//构建数据
			$("#reportUsergroupTbody").html("");
			
			var optionhtml = "";
			for(var index = 0 ; listDatas != null && index < listDatas.length ; index++) {
				var userperformance = listDatas[index];
				optionhtml += "<tr>";
				optionhtml += "<td>" + userperformance.realName + "[" + userperformance.workNumber + "]</td> ";
				optionhtml += "<td>" + userperformance.storeName + "</td>";
				optionhtml += "<td>" + userperformance.realTotalIntegral + "</td>";
				optionhtml += "<td>" + userperformance.realTotalAmount + "</td>";
				optionhtml += "</tr>";
			}
			$("#reportUsergroupTbody").html(optionhtml);
			
			//构造上一页和下一页选项
			var optionhtml = "<ul>";
			if(pageNum != 0) {
				optionhtml += "<li><a href=\"javascript:void(0)\" onclick=\"queryCompanyReportPerformance(" + (pageNum-1) + ")\">&lt;&lt; Prev</a></li>";
			}
			if(listDatas != null && listDatas.length == maxrow) {
				optionhtml += "<li><a href=\"javascript:void(0)\" onclick=\"queryCompanyReportPerformance(" + (pageNum+1) + ")\">Next &gt;&gt;</a></li>";
			}
			optionhtml += "</ul>";
			$("#userperformancepagination").html(optionhtml);
		}
	});
	
	
}
</script>
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
	<script src="${prefix}/javascripts/html5.js"></script>
<![endif]-->
<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="${prefix}/lib/font-awesome/docs/assets/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" href="${prefix}/lib/font-awesome/docs/assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="${prefix}/lib/font-awesome/docs//assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="${prefix}/lib/font-awesome/docs//assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="${prefix}/lib/font-awesome/docs//assets/ico/apple-touch-icon-57-precomposed.png">
</head>

<!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->
<!--[if IE 7 ]> <body class="ie ie7"> <![endif]-->
<!--[if IE 8 ]> <body class="ie ie8"> <![endif]-->
<!--[if IE 9 ]> <body class="ie ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> 
<body>
<!--<![endif]-->

<div class="navbar">
	<%@ include file="/commonjsp/userbar.jsp"%>
</div>

<div class="container-fluid">
	<div class="row-fluid">
		<%@ include file="/commonjsp/mainmenu.jsp"%>
		<!-- 列表 -->
		<div class="span9">
			<!-- 列表头 -->
			<h1 class="page-title">公司级报表</h1>
			
			<!-- 公司树 -->
			<div class="well" style="width: 150px;height: 480px; float: left; margin-right:10px ; padding: 5px ; overflow-y:none ; overflow-x:none;">
				<input type="hidden" name="admin_name" id="admin_name" value="${admin.userName }"/>
				<input type="hidden" name="admin_level" id="admin_level" value="${admin.adminLevel }"/>
				<input type="hidden" name="admin_companyid" id="admin_companyid" value="${admin.company.uid }"/>
				<select style="width: 100% ; height: 100% ; border: 0px" multiple="multiple" name="companyandstoreSelect" id="companyandstoreSelect">
					
				</select>
			</div>
			
			<div class="well" style="float: left; min-width: 900px; margin-bottom: 5px ; padding-bottom: 10px">
				<label style="color: #FF0000;margin-left: 0px"><b>筛选：为了保证数据统计、财务结算的准确性，只有已经进行核算的数据才会参与报表统计</b></label>
				<label style="adding-right: 10px">
					办理人工号：<input id="workNumber" type="text" value="" style="width: 120px; height: 30px"/>
				</label>
				<label style="float: left; ppadding-right: 10px">
					报表起始时间：<input type="text" id="beginFilingTime" value="" style="margin-right:10px; width: 120px; height: 30px"/>
				</label>
				<label style="float: left; padding-right: 10px">
					报表截止时间：<input type="text" id="endFilingTime" value="" style="margin-right:10px;width: 120px; height: 30px"/>
				</label>
				<label style="padding-right: 10px">
					<a id="savebutton" href="javascript:void(0);" onclick="queryCompanyReport(0);queryCompanyReportPerformance(0);" class="btn btn-primary" >Search</a>
				</label>
			</div>
			
			<!-- 列表正文 -->
			<div class="well" style="float: left; min-width: 900px; margin-top: 5px">
				<ul class="nav nav-tabs">
					<li class="active"><a href="#home" data-toggle="tab">工单任务</a></li>
					<li><a href="#usergroupdiv" data-toggle="tab">人员业绩</a></li>
				</ul>
				
				<div id="myTabContent" class="tab-content">
					<div class="tab-pane active in" id="home">
					<table class="table">
						<thead>
							<tr>
								<th>工单类型</th> 
								<th>核算积分</th>
								<th>核算金额</th>
								<th>核算时间</th>
								<th>办理人</th>
							</tr>
						</thead>
						<tbody id="reportResultTbody">
							<tr>
								<td colspan="6">
									请填写报表条件后，点击“search”按钮进行查询。
								</td>
							</tr>
						</tbody>
					</table>
					<!-- 分页信息 -->
					<div class="pagination" id="listpagination">
					    
					</div>
					</div>
					
					<!-- 人员业绩分类统计 -->
					<div class="tab-pane fade" id="usergroupdiv">
						<table class="table">
							<thead>
								<tr>
									<th>人员</th>
									<th>所属店面</th>  
									<th>总核算积分</th>
									<th>总核算金额</th>
								</tr>
							</thead>
							<tbody id="reportUsergroupTbody">
								<tr>
									<td colspan="4">
										请填写报表条件后，点击“search”按钮进行查询。
									</td>
								</tr>
							</tbody>
						</table>
						
						<!-- 分页信息 -->
						<div class="pagination" id="userperformancepagination">
						    
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<!-- Le javascript
	================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->
	<script src="${prefix}/lib/bootstrap/js/bootstrap.js"></script>
</div>
</body>
</html>